{% extends 'base.html' %}
{% load static %}

{% block title %}个人资料 - Creeps Judge{% endblock %}

{% block extra_css %}
<style>
    .page-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 40px 0;
        margin-bottom: 30px;
        text-align: center;
    }
    
    .page-header h1 {
        font-size: 2.5rem;
        font-weight: 300;
        margin-bottom: 10px;
    }
    
    .page-header p {
        font-size: 1.1rem;
        opacity: 0.9;
        margin: 0;
    }
    
    .profile-container {
        max-width: 1000px;
        margin: 20px auto;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        border-radius: 20px;
        padding: 40px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        margin-bottom: 30px;
    }
    
    .profile-header {
        text-align: center;
        margin-bottom: 40px;
        padding-bottom: 30px;
        border-bottom: 2px solid rgba(74, 144, 226, 0.2);
    }

    .avatar-container {
        margin-bottom: 20px;
    }

    .avatar {
        width: 120px;
        height: 120px;
        border-radius: 50%;
        object-fit: cover;
        border: 4px solid #4a90e2;
        box-shadow: 0 8px 16px rgba(74, 144, 226, 0.3);
    }

    .default-avatar {
        width: 120px;
        height: 120px;
        border-radius: 50%;
        background: linear-gradient(135deg, #4a90e2, #357abd);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 48px;
        font-weight: bold;
        margin: 0 auto;
        box-shadow: 0 8px 16px rgba(74, 144, 226, 0.3);
    }

    .username {
        font-size: 32px;
        font-weight: bold;
        color: #2c3e50;
        margin-bottom: 8px;
    }

    .user-title {
        font-size: 16px;
        color: #7f8c8d;
        font-weight: 500;
    }

    /* 统计信息卡片 */
    .profile-stats {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 20px;
        margin-bottom: 40px;
    }

    .stat-card {
        background: rgba(255, 255, 255, 0.8);
        border-radius: 15px;
        padding: 25px;
        text-align: center;
        border: 1px solid rgba(74, 144, 226, 0.1);
        transition: all 0.3s ease;
        backdrop-filter: blur(5px);
    }

    .stat-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 15px 30px rgba(74, 144, 226, 0.2);
        border-color: rgba(74, 144, 226, 0.3);
    }

    .stat-icon {
        font-size: 32px;
        color: #4a90e2;
        margin-bottom: 15px;
    }

    .stat-value {
        font-size: 28px;
        font-weight: bold;
        color: #2c3e50;
        margin-bottom: 8px;
    }

    .stat-label {
        font-size: 14px;
        color: #7f8c8d;
        font-weight: 500;
    }

    /* 信息网格 */
    .info-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 25px;
        margin-bottom: 30px;
    }

    .info-card {
        background: rgba(255, 255, 255, 0.8);
        border-radius: 15px;
        padding: 25px;
        border: 1px solid rgba(74, 144, 226, 0.1);
        transition: all 0.3s ease;
        backdrop-filter: blur(5px);
    }

    .info-card:hover {
        transform: translateY(-3px);
        box-shadow: 0 10px 25px rgba(74, 144, 226, 0.15);
        border-color: rgba(74, 144, 226, 0.3);
    }

    .info-header {
        display: flex;
        align-items: center;
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 2px solid rgba(74, 144, 226, 0.1);
    }

    .info-icon {
        font-size: 20px;
        color: #4a90e2;
        margin-right: 12px;
        width: 24px;
        text-align: center;
    }

    .info-title {
        font-size: 18px;
        font-weight: bold;
        color: #2c3e50;
    }

    .info-content p {
        margin-bottom: 12px;
        line-height: 1.6;
        color: #34495e;
    }

    .info-content p:last-child {
        margin-bottom: 0;
    }

    .text-muted {
        color: #95a5a6 !important;
        font-style: italic;
    }

    /* 个人简介卡片 */
    .bio-card {
        background: rgba(255, 255, 255, 0.8);
        border-radius: 15px;
        padding: 25px;
        margin-bottom: 30px;
        border: 1px solid rgba(74, 144, 226, 0.1);
        backdrop-filter: blur(5px);
    }

    .bio-header {
        display: flex;
        align-items: center;
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 2px solid rgba(74, 144, 226, 0.1);
    }

    .bio-icon {
        font-size: 20px;
        color: #4a90e2;
        margin-right: 12px;
        width: 24px;
        text-align: center;
    }

    .bio-title {
        font-size: 18px;
        font-weight: bold;
        color: #2c3e50;
    }

    .bio-content {
        line-height: 1.8;
        color: #34495e;
        font-size: 15px;
    }

    /* 现代化按钮样式 */
    .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 15px;
        justify-content: center;
        margin-top: 30px;
    }

    .btn-gradient {
        background: linear-gradient(135deg, #4a90e2, #357abd);
        color: white;
        padding: 12px 24px;
        border-radius: 25px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        box-shadow: 0 4px 15px rgba(74, 144, 226, 0.3);
    }

    .btn-gradient:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(74, 144, 226, 0.4);
        color: white;
        text-decoration: none;
    }

    .btn-warning {
        background: linear-gradient(135deg, #f39c12, #e67e22);
        color: white;
        padding: 12px 24px;
        border-radius: 25px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        box-shadow: 0 4px 15px rgba(243, 156, 18, 0.3);
    }

    .btn-warning:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(243, 156, 18, 0.4);
        color: white;
        text-decoration: none;
    }

    .btn-outline {
        background: transparent;
        color: #4a90e2;
        padding: 12px 24px;
        border: 2px solid #4a90e2;
        border-radius: 25px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 8px;
    }

    .btn-outline:hover {
        background: #4a90e2;
        color: white;
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(74, 144, 226, 0.3);
        text-decoration: none;
    }

    .btn-danger {
        background: linear-gradient(135deg, #e74c3c, #c0392b);
        color: white;
        padding: 12px 24px;
        border-radius: 25px;
        text-decoration: none;
        font-weight: 600;
        transition: all 0.3s ease;
        border: none;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 8px;
        box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
    }

    .btn-danger:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px rgba(231, 76, 60, 0.4);
        color: white;
    }

    .breadcrumb-nav {
        background: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(10px);
        padding: 12px 20px;
        border-radius: 8px;
        margin: 20px auto;
        margin-bottom: 20px;
        border: 1px solid rgba(255, 255, 255, 0.2);
        max-width: 1000px;
    }

    .breadcrumb-nav a {
        color: #667eea;
        text-decoration: none;
        font-weight: 500;
        display: inline-flex;
        align-items: center;
        gap: 8px;
    }

    .breadcrumb-nav a:hover {
        text-decoration: underline;
    }

    @media (max-width: 768px) {
        .profile-container {
            margin: 10px;
            padding: 20px;
        }

        .profile-stats {
            grid-template-columns: 1fr;
        }
        
        .info-grid {
            grid-template-columns: 1fr;
        }
        
        .action-buttons {
            flex-direction: column;
            align-items: center;
        }

        .action-buttons > * {
            width: 100%;
            max-width: 300px;
            justify-content: center;
        }

        .username {
            font-size: 24px;
        }

        .stat-value {
            font-size: 24px;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="page-header">
    <div class="container">
        <h1><i class="fas fa-user-circle"></i> 个人资料</h1>
        <p>管理您的个人信息和账户设置</p>
    </div>
</div>

<div class="container">
    <div class="breadcrumb-nav">
        <a href="/"><i class="fas fa-home"></i> 返回首页</a>
    </div>
    
    <div class="profile-container">

        <div class="profile-header">
            <div class="avatar-container">
                {% if user.profile.avatar %}
                    <img src="{{ user.profile.avatar.url }}" alt="头像" class="avatar">
                {% else %}
                    <div class="default-avatar">
                        {{ user.username|first|upper }}
                    </div>
                {% endif %}
            </div>
            <div class="username">{{ user.username }}</div>
            <div class="user-title">Creeps Judge 用户</div>
        </div>

        <!-- 统计信息卡片 -->
        <div class="profile-stats">
            <div class="stat-card">
                <div class="stat-icon">
                    <i class="fas fa-code"></i>
                </div>
                <div class="stat-value">{{ user.code_set.count|default:0 }}</div>
                <div class="stat-label">代码项目</div>
            </div>
            
            <div class="stat-card">
                <div class="stat-icon">
                    <i class="fas fa-trophy"></i>
                </div>
                <div class="stat-value">{{ user.battle_set.count|default:0 }}</div>
                <div class="stat-label">参与对战</div>
            </div>
            
            <div class="stat-card">
                <div class="stat-icon">
                    <i class="fas fa-calendar-alt"></i>
                </div>
                <div class="stat-value">{{ user.date_joined|date:"Y-m-d" }}</div>
                <div class="stat-label">加入时间</div>
            </div>
        </div>

        <!-- 详细信息网格 -->
        <div class="info-grid">
            <div class="info-card">
                <div class="info-header">
                    <div class="info-icon">
                        <i class="fas fa-user"></i>
                    </div>
                    <div class="info-title">基本信息</div>
                </div>
                <div class="info-content">
                    <p><strong>用户名：</strong>{{ user.username }}</p>
                    <p><strong>姓名：</strong>
                        {% if user.first_name or user.last_name %}
                            {{ user.first_name }} {{ user.last_name }}
                        {% else %}
                            <span class="text-muted">未设置</span>
                        {% endif %}
                    </p>
                    <p><strong>注册时间：</strong>{{ user.date_joined|date:"Y年m月d日 H:i" }}</p>
                </div>
            </div>

            <div class="info-card">
                <div class="info-header">
                    <div class="info-icon">
                        <i class="fas fa-envelope"></i>
                    </div>
                    <div class="info-title">联系方式</div>
                </div>
                <div class="info-content">
                    <p><strong>电子邮箱：</strong>
                        {% if user.email %}
                            {{ user.email }}
                        {% else %}
                            <span class="text-muted">未设置</span>
                        {% endif %}
                    </p>
                    <p><strong>所在地：</strong>
                        {% if user.profile.location %}
                            {{ user.profile.location }}
                        {% else %}
                            <span class="text-muted">未设置</span>
                        {% endif %}
                    </p>
                </div>
            </div>

            <div class="info-card">
                <div class="info-header">
                    <div class="info-icon">
                        <i class="fas fa-birthday-cake"></i>
                    </div>
                    <div class="info-title">个人资料</div>
                </div>
                <div class="info-content">
                    <p><strong>出生日期：</strong>
                        {% if user.profile.birth_date %}
                            {{ user.profile.birth_date|date:"Y年m月d日" }}
                        {% else %}
                            <span class="text-muted">未设置</span>
                        {% endif %}
                    </p>
                    <p><strong>最后登录：</strong>
                        {% if user.last_login %}
                            {{ user.last_login|date:"Y年m月d日 H:i" }}
                        {% else %}
                            <span class="text-muted">从未登录</span>
                        {% endif %}
                    </p>
                </div>
            </div>
        </div>

        <!-- 个人简介 -->
        {% if user.profile.bio %}
        <div class="bio-card">
            <div class="bio-header">
                <div class="bio-icon">
                    <i class="fas fa-quote-left"></i>
                </div>
                <div class="bio-title">个人简介</div>
            </div>
            <div class="bio-content">{{ user.profile.bio|linebreaks }}</div>
        </div>
        {% endif %}

        <!-- 操作按钮 -->
        <div class="action-buttons">
            <a href="{% url 'accounts:edit_profile' %}" class="btn-gradient">
                <i class="fas fa-edit"></i> 编辑资料
            </a>
            <a href="{% url 'accounts:change_password' %}" class="btn-warning">
                <i class="fas fa-key"></i> 修改密码
            </a>
            <a href="{% url 'codes:code_list' %}" class="btn-outline">
                <i class="fas fa-code"></i> 我的代码
            </a>
            <form method="post" action="{% url 'accounts:logout' %}" style="display: inline;">
                {% csrf_token %}
                <button type="submit" class="btn-danger">
                    <i class="fas fa-sign-out-alt"></i> 退出登录
                </button>
            </form>
        </div>
    </div>
</div>
{% endblock %}